# Sept 2023
# Set an empty (or not exported) Object name (not a sub object) with:
#  #SCRIPT# DIR 
# It will run that batch file. IE:
# #SCRIPT# C:\Program Files\MarbleCLAY\Plugin\RunBatchScript.txt
# When entering the #SCRIPT# path\file.txt into the object name field, hit enter to update the name change after changing the name.
# The default assetpath will be the path this file is located.
# 
# If #SCRIPT# is not set, the default will be this file:
# C:\MarbleCLAY\Plugin\RunBatchScript.txt 

# runbatchscript for MarbleClay PlayStation export.
# RSD Export/Obj batch script version 2 (May 2023)
# No warranty or liablity, very hacky stuff! Use at own risk.

# No defaulting of values below, all parameter values must appear!

# !assetpath C:\Documents and Settings\NetYaroze\Desktop
# This should be the first line executed!
# Spaces are fine in path, but dont put in quotes or a last back slash.
# Path can be change anytime, and the following commands will process in that folder.

# !rsdexport RootObjectName 1234567.rsd 1.0 0/1/2
# Names are Alphanumeric, no path included, no spaces, filename must be 7.3 formatted or less, 1.0 is the scale value, 0/1/2 can either be: 1:launch No$PSX,  0:Create TMD but skip No$PSX, or 2:ask
# See RSDExporter.txt for more information.
# !objexport is the same, except there is no launchpsx - note: no normals are exported.

#  !echo off / on
# Default is on, each DOS command's output will be displayed in a message popup, if off, it wont. 


# !quit or !exit
# stops, and quits execution


# Everything else will be DOS commands and each passed to DOS, run in the current (!assetpath) location.
# Your commands can be log your output by >>file.log,  >NUL  2>NUL to null or everything will be displayed with !echo on.

#Recommendations :
# Using folders and files with no spaces, ASCII char's and DOS (or 7.3) filenames.
# Use echo on to see command and output when editing this script.
# You can not save this script while MarbleClay is running this script! Wait for it to end first.
# CD (chdir) will have no effect after that line has exectuted, you must use the !assetpath command.
# WARNING - strongly advise not deleting anything via this script, instead use move, if you have to run delete, always fully qualify individual files to avoid removing wrong files.
# Sometimes the message boxes from MarbleClay will be behind the application and it will look like it's locked up or crashed, it hasn't just hit Alt + Tab to find it, Also you'll see two MarbleClay windows in the toolbar, click the 2nd one.
# If you run a command and it's halted or pause (ie awaiting input), it will need to be killed via process explorer, for the script to finish.

#turn logging off  
@echo starting - wait a few seconds.
!echo off


# rm,cp etc are from https://github.com/skeeto/w64devkit (busybox-w32 : standard unix utilities, including sh)

rm -rf tmd
!assetpath  tmd


#create the frames to animate
!rsdexport F2 f1.rsd 10.0  0
!rsdexport F1 f2.rsd 10.0  0
!rsdexport F2 f3.rsd 10.0  0
!rsdexport F3 f4.rsd 10.0  0

!objexport F2 f1.obj 1.0  
!objexport F1 f2.obj 1.0  
!objexport F2 f3.obj 1.0  
!objexport F3 f4.obj 1.0  

rsd2tmd f1 1
rsd2tmd f2 1
rsd2tmd f3 1
rsd2tmd f4 1

mkdir anim
cp f1.tmd anim
cp f2.tmd anim
cp f3.tmd anim
cp f4.tmd anim
!assetpath  anim


#create the frames to animate
pwd > tmdanim.txt
tmdanim -L -t3 -MM -v -nn -s08 >> tmdanim.txt

cp -f TMD_ANIM.PCK walk.pck
cp -f  walk.pck ../../../../tmd
cp -f  walk.pck ../../../../tmd
echo copying TMD with normals and lights >> tmdanim.txt
cp -f  f1.tmd ../../../../tmd
cp -f  f0.mm ../../../../tmd
cp -f  tmdanim.txt ../../../../tmd
pwd

# cd C:\NY-WS\tmdanim\tmd
!assetpath  ..
pwd
!assetpath  ..
pwd
!assetpath  ..
pwd
!assetpath  ..
pwd


echo "make and run!" >> log.txt
wincmd cmd /C "make clean && make PSX >> log.txt"
